package com.cneiu.ppms.web.action;

import com.cneiu.ppms.web.base.BaseController;
import com.cneiu.ppms.web.model.MeterModel;
import com.cneiu.ppms.web.service.MeterService;
import com.jfinal.plugin.activerecord.Page;
/**
 * 电表Controller
 * @author zhaokf
 * @date 2013-04-19
 */
public class MeterController extends BaseController
{
	/**
	 * 获取page limit得到电表列表(已测试)
	 */
	public void list(){
		Page<MeterModel> Meters = MeterService.list(this.getParams());
		if (null != Meters){
			renderGrid(Meters.getTotalRow(), Meters.getList());
		}else{
			renderAjax(false, MeterService.getError());
		}
	}
	
	/**
	 * 根据ID查询电表(已测试)
	 */
	public void get(){
		try{
			MeterModel model = MeterService.get(this.getParams());
			renderGrid(model);
		}catch (Exception e){
			e.printStackTrace();
		}
	}

	/**
	 * 添加电表(已测试)
	 */
	public void add(){
		try{
			if(!MeterService.isAdd(this.getParams())){
				renderAjax(false, MeterService.getError());
			}else{
				renderAjax(true, "添加电表成功");
			}
		}
		catch (Exception e){
			e.printStackTrace();
		}
	}

	/**
	 * 编辑电表(已测试)
	 */
	public void edit(){
		try{
			if(!MeterService.isUpdate(this.getParams())){
				renderAjax(false, MeterService.getError());
			}else{
				renderAjax(true, "编辑电表成功");
			}
		}catch (Exception e){
			e.printStackTrace();
		}
	}
	
	/**
	 * 删除电表(已测试)
	 */
	public void delete(){
		try{
			if(!MeterService.isDelete(this.getParams())){
				renderAjax(false, MeterService.getError());
			}else{
				renderAjax(true, "删除电表成功");
			}
		}catch (Exception e){
			e.printStackTrace();
		}
	}
}
